package Servlet;

import DAO.DAOFactory;
import DAO.PackageDAO;
import javabean.Package;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/PackageManager")
public class PackageManagerServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding( "UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        PackageDAO packageDAO = (PackageDAO) DAOFactory.getPackageDAOInstance();
        List<Package> packages = null;
        try {
            packages = packageDAO.getAllPackages();
            req.setAttribute("packages",packages);
            req.getRequestDispatcher("PackageManager.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
